package game;

import java.util.Stack;

public class StackBoard extends TicTacToeBoard {
	
	public static final int X = 0; 
	public static final int O = 1; 
	public static final int EMPTY = -1; 

	public Stack<Integer> stackBoard = new Stack<Integer>(); 
	
	public void createGrid(){
		for(int i = 0; i < 8; i++){
			stackBoard.push(EMPTY); 
		}
		
	}
	
	protected void makeMove(int s, int m){
		int[] b = new int[9]; 
		for(int i = 0; i< s; i++){
			b[i] = stackBoard.pop(); 
		}
		b[s] = m;  
		for(int j = s; j > 0; j--){
			stackBoard.push(b[j]); 
		}
	}

	public int getValue(int s){
		for(int i = 0; i<s; i++){
			if(i == s){
				int x = stackBoard.pop(); 
				return x; 
			} else { 
				stackBoard.pop(); 	
			}
		} 
		return 0; 
	}
	
	public boolean checkFree(int s){
		int[] b = new int[s];
		for(int i = 0; i < s; i++){
			b[i] = stackBoard.pop(); 
		}
		if(b[s] == EMPTY){ 
			return true; 
		} else {
			return false; 
		} 
	}
	
	public void reset(){
		for(int i = 0; i < 8; i++){
			stackBoard.pop(); 
		}
		for(int j = 0; j<8; j++){
			stackBoard.push(EMPTY); 
		}
	}
} 
